﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using Foundation;
using ILRuntime.Mono.Cecil;
using ILRuntime.Mono.Cecil.Cil;
using Newtonsoft.Json.Linq;
using Scriban;
using Scriban.Runtime;
using UIKit;

[assembly : AssemblyVersion("1.0.*")]

namespace mb.iOS
{
    public class Application
    {
        static void Main(string[] args)
        {
            App.Initialize();

            var so = ServiceLocator.Instance.Get<API.IStartOption>();
            so.LoadStartOption();

            if (so.GetValue<bool>("ilrgen"))
            {
                UIApplication.Main(args, null, "AppDelegateGenBind");
                return;
            }

            try
            {
                UIApplication.Main(args, null, "AppDelegate");
            }
            catch (Exception e)
            {
                App.logger.Log("------Catch Exception in Main-------");
                App.logger.Log(e.ToString());
                App.logger.Log("ilr.stacktrace", e.Data["StackTrace"]?.ToString());
                if (e.InnerException != null)
                    App.logger.Log(e.InnerException.ToString());
                App.logger.Log("------------------------------------");
            }
        }

    }
}